package com.tngames.angrytunisian.game.core.splingshot;

import org.jbox2d.common.Vec2;

import playn.core.Image;

import com.tngames.angrytunisian.game.core.Constants;
import com.tngames.angrytunisian.game.core.Resources;
import com.tngames.angrytunisian.game.core.entity.Entity;
import com.tngames.angrytunisian.game.core.entity.EntityEngine;

public class SlingShot extends Entity {

	private static final String IMAGE = Resources.SLING_SHOT;
	private static final float HEIGHT = 200 * Constants.PHYS_UNIT_PER_SCREEN_UNIT;
	private static final float WIDTH = 80 * Constants.PHYS_UNIT_PER_SCREEN_UNIT;

	public SlingShot(EntityEngine entityEngine, float x, float y) {
		super(entityEngine, x, y, 0);
	}

	@Override
	public float getWidth() {
		return WIDTH;
	}

	@Override
	public float getHeight() {
		return HEIGHT;
	}

	public Vec2 getOnSpringPositionOne() {
		return new Vec2(32, 22);
	}

	public Vec2 getOnSpringPositionTwo() {
		return new Vec2(32, 64);
	}

	public Vec2 getCenterPosition() {
		return new Vec2(32 * Constants.PHYS_UNIT_PER_SCREEN_UNIT,
				21 * Constants.PHYS_UNIT_PER_SCREEN_UNIT);
	}

	public Vec2 getAbsoluteCenterPosition() {
		float a1 = getPosX();
		float b1 = getImage().width() * Constants.PHYS_UNIT_PER_SCREEN_UNIT;
		float vecX = a1 - b1 / 2 + 32 * Constants.PHYS_UNIT_PER_SCREEN_UNIT;

		float a2 = getPosY();
		float b2 = getImage().height() * Constants.PHYS_UNIT_PER_SCREEN_UNIT;
		float vecY = a2 - b2 / 2 + 21 * Constants.PHYS_UNIT_PER_SCREEN_UNIT;
		return new Vec2(vecX, vecY);
	}

	@Override
	public void initPreLoad(EntityEngine entityEngine) {
		// TODO Auto-generated method stub

	}

	@Override
	public void initPostLoad(EntityEngine entityEngine) {
		entityEngine.staticLayerBack.add(layer);
	}

	@Override
	public Image getImage() {
		return loadImage(IMAGE);
	}

}
